define(function (){
    function createCharts(obj, data, data2, titleTxt, subTitle, seriesName, colorCode, lineCode, tickintv, carLicPltNo){
        obj.highcharts({
            chart: {
                zoomType: 'x',
                spacingRight: 20,
                width: 750
            },
            title: {
                text: carLicPltNo+titleTxt
            },
            xAxis: {
                type: 'datetime',
                maxZoom: 15*1000,
                //tickInterval: tickintv,
                title: {
                    text: null
                }
                //categories: timeArr
            },
            yAxis: [{
                labels: {

                    style: {
                        color: '#89A54E'
                    }
                },
                title: {
                    text: '总电压(v)',
                    style: {
                        color: '#89A54E'
                    }
                },
                //min:0, // 定义最小值
                opposite: true
            }, {
                gridLineWidth: 0,
                title: {
                    text: '总电流(A)',
                    style: {
                        color: '#4572A7'
                    }
                },
                //min:0, // 定义最小值
                labels: {

                    style: {
                        color: '#4572A7'
                    }
                }
            }],
            credits:{
                enabled:false
            },

            tooltip: {
                shared: true
            },
            legend: {
                enabled: false
            },
            plotOptions: {
                area: {
                    color:lineCode,
                    fillColor: {
                        linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
                        stops: [
                            [0, Highcharts.getOptions().colors[colorCode]],
                            [1, Highcharts.Color(Highcharts.getOptions().colors[colorCode]).setOpacity(0).get('rgba')]
                        ]
                    },
                    lineWidth: 1,
                    marker: {
                        enabled: false
                    },
                    shadow: false,
                    states: {
                        hover: {
                            lineWidth: 1
                        }
                    },
                    threshold: null
                }
            },

            series: [{
                name: '总电流(A)',
                color: '#4572A7',
                type: 'spline',
                yAxis: 1,
                data: data
            }, {
                name: '总电压(v)',
                color: '#89A54E',
                type: 'spline',
                data: data2
            }]
        });
    };

    // DOIT: 2016-12-23 电池-电压电流图表
    
    var voltageAnaly=function(params,initChart,chartWithoutData,$dataChart){
        initChart();
        $.ajaxExt({
            url : "/batteryStatus/voltageAnalysis.htm",
            data:params
        }).done(function(result){
            if(!result){
                chartWithoutData();
                return;
            }
            var selLicPltNo = result[0].licPltNo;
            var tickIntv = parseInt(result.length/4);//横轴密度
            var spdData = [],eMSpdData = [];
            $.each(result, function (i) {
                var time = result[i].rcrdTime, date;
                var date = "Date.UTC(" + time.substr(0, 4) + "," + time.substr(5, 2) + "," + time.substr(8, 2) + "," + time.substr(11, 2) + "," + time.substr(14, 2) + "," + time.substr(17, 2) + ")";
//                if(result[i].totalEltCrt < 100){
//                	console.info(result[i].totalEltCrt);
//                }
                spdData.push(eval("[" + date + "," + result[i].totalEltCrt + "]"));
                eMSpdData.push(eval("[" + date + "," + result[i].totalVtg + "]"));
            });
            createCharts($dataChart, spdData, eMSpdData, "电流电压分析(" + params.beginTime + ")", "总电流(A)", "总电流(A)", 2, '#489648', tickIntv, selLicPltNo);
        });
    };
    function createMultiCharts(obj, data1, data2, yymmdd, tickintv, selLicPltNo){
        obj.highcharts({
            chart: {
                zoomType: 'x',
                spacingRight: 20,
                width: 750
            },
            title: {
                text: selLicPltNo + '续航里程图表' + yymmdd
            },
            subtitle: {
            },
            credits: {
                enabled: false
            },
            xAxis: {
                type: 'datetime',
                maxZoom: 15*1000,
                title: {
                    text: null
                }
            },
            yAxis: [{
                labels: {

                    style: {
                        color: '#89A54E'
                    }
                },
                title: {
                    text: '续航里程',
                    style: {
                        color: '#89A54E'
                    }
                },
                min:0, // 定义最小值
                opposite: true
            }, {
                gridLineWidth: 0,
                title: {
                    text: 'SOC',
                    style: {
                        color: '#4572A7'
                    }
                },
                min:0, // 定义最小值
                labels: {

                    style: {
                        color: '#4572A7'
                    }
                }
            }],
            series: [{
                name: 'SOC',
                color: '#4572A7',
                type: 'spline',
                yAxis: 1,
                data: data1
            }, {
                name: '续航里程',
                color: '#89A54E',
                type: 'spline',
                data: data2
            }]
        });
    };

    // DOIT: 2016-12-23 电池-续航里程分析
    
    enduranceMile=function(params,initChart,chartWithoutData,$dataChart){
        initChart();
        $.ajaxExt({
            url : "/batteryStatus/socCharts.htm",
            data:params
        }).done(function(result){
            if(!result){
                chartWithoutData();
                return;
            }
            selLicPltNo = result[0].licPltNo;
            var tickIntv = parseInt(result.length/4);//横轴密度
            var spdData = [],eMSpdData = [];
            debugger;
            $.each(result,function(i){
                var time = result[i].rcrdTime,date;
                date = "Date.UTC(" + time.substr(0, 4) + "," + time.substr(5, 2) + "," + time.substr(8, 2) + "," + time.substr(11, 2) + "," + time.substr(14, 2) + "," + time.substr(17, 2) + ")";
                spdData.push(eval("[" + date + "," + result[i].soc + "]"));
                eMSpdData.push(eval("[" + date + "," + result[i].durationMile + "]"));
            });
            createMultiCharts($dataChart, spdData, eMSpdData, "("+params.beginTime+")", tickIntv, selLicPltNo);
        });
    };
    return {
        voltageAnaly: voltageAnaly,
        enduranceMile:enduranceMile
    };
});